# -*- coding: utf-8 -*-


import re
import sys
import warnings
import argparse
warnings.filterwarnings("ignore")
    
def openfile(filename):
    result = ""
    with open(filename,'r',encoding="utf-8") as f:
        result = f.read()
    return result

def getfilename(filename):
    result = filename
    indexSlant = -1
    try:
        indexSlant = filename.rindex("\\")
    except:
        pass
    indexExt = -1
    try:
        indexExt = filename.rindex("xml")
    except:
        pass
    if indexExt != -1 and indexExt !=-1:
        result = filename[indexSlant + 1:indexExt-1]
    return result

def genContractCode(contractName):
    readtext=""
     #'d:\\fenlei2.xml'
    if contractName == "":
        return 
    readtext = openfile("template/TemplateContract.kt")
    readtext = readtext.replace("[ContractName]",contractName)
    print(readtext)
    
    
if __name__ == '__main__':
     # 配置支持的参数
    parser = argparse.ArgumentParser("生成 Contract 代码")
    parser.add_argument('--name',help="设置 contract 名称")
    
    if len(sys.argv) < 2:
        print("生成 Contract 代码")
        print()
        print("  --name: Contract 名称")
    else:    
        # 参数解析
        args = parser.parse_args()
        contractName = ""
        if args.name:
            contractName = args.name
        #'d:\\fenlei2.xml'
        genContractCode(contractName)
